package coc.example.config;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

import coo.base.model.Params;

public class ParamsConverter implements Converter {
	@SuppressWarnings("rawtypes")
	@Override
	public boolean canConvert(Class targetClass) {
		return targetClass == Params.class;
	}

	@Override
	public void marshal(Object source, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		Params params = (Params) source;
		writer.setValue(params.toString());
	}

	@Override
	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		Params params = new Params();
		params.fromString(reader.getValue());
		return params;
	}
}
